def pr(n):
    t=True
    for i in range (2,int(n**0.5)+1):
        if n%i==0:
            t=False
    return t

s = input()
alf = ['zero','one','two','three','four','five','six','seven','eight','nine']
s=s.split()
if (s[0] in alf) and (s[1] in alf) and (s[2] in alf):
    ch = alf.index(s[0])*100+ alf.index(s[1])*10+ alf.index(s[2])
    if pr(ch):
        p=ch
    else:
        for i in range(ch-1,2,-1):
            if pr(i):
                p=i
                break
        for i in range(ch+1,1500):
            if pr(i) and (ch - p)>(i-ch):
                p=i
                break
            
    print(p)
else:
    print('Wrong input')
